package org.easymis.oa.modules.main.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.easymis.entitys.mybatis.dto.Member;
import org.easymis.entitys.mybatis.dto.OaDiary;
import org.easymis.entitys.mybatis.dto.OrganizeFunction;
import org.easymis.oa.service.datacenter.OrganizeFunctionMng;
import org.easymis.oa.service.main.OaDiaryMng;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * 
 * @See 个人日志
 *
 */
@Controller
@RequestMapping("/diary/month/")
public class OaDiaryMonthAction {
	@Resource
	private OaDiaryMng service;
	@Autowired
	OrganizeFunctionMng organizeFunctionMng;
	@RequestMapping(value = "index")
	public String index(HttpServletRequest request, HttpSession session,ModelMap model) throws Exception {
		request.setAttribute("base", "http://demo.easymis.cn");
		String functionId=request.getParameter("menuId");
		List<OrganizeFunction> breadcrumbList= organizeFunctionMng.getBreadcrumb(functionId);
		request.setAttribute("base", "http://demo.easymis.cn/oa");
		model.put("breadcrumbList", breadcrumbList);
		return "/diary/month/index";
	}
	@RequestMapping(value = "myQuery")
	public String forwardIndex(HttpServletRequest request, HttpSession session,ModelMap model) throws Exception {
		request.setAttribute("base", "http://demo.easymis.cn");
		String functionId=request.getParameter("menuId");
		List<OrganizeFunction> breadcrumbList= organizeFunctionMng.getBreadcrumb(functionId);
		request.setAttribute("base", "http://demo.easymis.cn/oa");
		model.put("breadcrumbList", breadcrumbList);
		return "/diary/month/myQuery";
	}

	@RequestMapping(value = "grid", method = RequestMethod.POST)
	public String forwardList(int page, int rows, HttpServletRequest request) throws Exception {
		OaDiary bean = new OaDiary();
		//bean.setOrgId(orgId);
		List diaryList=service.getList(bean);
		request.setAttribute("OaDiary_list", diaryList);
		return "/diary/month/grid";
	}
	@RequestMapping(value = "save", method = RequestMethod.POST)
	@ResponseStatus(value = HttpStatus.OK)
	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm")
	public void save(HttpServletRequest request, HttpSession session, OaDiary bean) throws Exception {
		Member userInfo =(Member)session.getAttribute("userInfo");

		bean.setOrgId(userInfo.getOrgId());
		bean.setStaffId(userInfo.getStaffId());
		bean.setType(2);
		bean.setStatus(1);
		bean.setReviewWorkLevel(0);
		
		service.save(bean);

	}
	@RequestMapping(value = "delete", method = RequestMethod.POST)
	@ResponseStatus(value = HttpStatus.OK)
	public void delete(HttpServletRequest request, String id) throws Exception {		
		service.delete(id);
	}
	@RequestMapping(value = "update", method = RequestMethod.POST)
	@ResponseStatus(value = HttpStatus.OK)
	public void updateaddressarea(HttpServletRequest request, HttpSession session) throws Exception {
		String id = request.getParameter("id");
		OaDiary bean = service.findById(id);
		service.update(bean);
	}
	@RequestMapping(value = "deleteByIds", method = RequestMethod.POST)
	@ResponseStatus(value = HttpStatus.OK)
	@ResponseBody
	public String deleteByIds(HttpServletRequest request) throws Exception {
		String ids_str = request.getParameter("id");
		String[] ids = ids_str.split(",");
		//service.deleteByIds(ids);
		
		return "";

	}
}
